class Singleton {
  // private - 外部无法初始化
  private constructor() {}

  // static 属性
  private static instance: Singleton | null;

  // static 方法
  static getInstance(): Singleton {
    if (Singleton.instance == null) {
      Singleton.instance = new Singleton();
    }
    return Singleton.instance;
  }
}

/** 闭包方式 */
function genGetInstance() {
  let instance: any; // 闭包

  class Singleton {}

  return () => {
    if (instance == null) {
      instance = new Singleton();
    }
    return instance;
  };
}

export {
  Singleton,
  genGetInstance
}
